package com.pool.common;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Container for all data about a shoot.
 * 
 * @author claveld@gmail.com (David Clavel)
 */
public class Record {

  private static final int IGNORE = -1;
  
  public final String id;
  public String timestamp;
  public String player;
  public String shootId;
  public int remainingBalls;

  public Record(String id, String timestamp, String player, String shootId) {
    this(id, timestamp, player, shootId, IGNORE);
  }
  
  public Record(String id, String timestamp, String player, String shootId, int remainingBalls) {
    this.id = id;
    this.timestamp = timestamp;
    this.player = player;
    this.shootId = shootId;
    this.remainingBalls = remainingBalls;
  }

  public static Record of(String player, String shootId, int remainingBalls) {
    Date now = new Date();
    SimpleDateFormat timestampFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
    String timestamp = timestampFormat.format(now);
    String id = Long.toString(now.getTime());
    
    return new Record(id, timestamp, player, shootId, remainingBalls);
  }
}
